var ns;
var app = new Vue({
    el: '#app',
    data: {
        ID:0,
        EncriptID:'',
        form: {
        },
        showdetail:false,
        activetab:1,
        //维保记录
        wbCount:0,
        wblist:[],
        //巡检记录
        xjCount:0,
        xjlist:[],
        //维修工单
        wxlist:[],
    },
    methods: {
        onDealTime(time) {
            return moment(time).format('YYYY-MM-DD') || '';
        },
        select_tab(value){
            this.activetab=value;
        },
        get_homedata(){
            var that = this;
            var options = {};
            options.DeviceID = that.ID;  
            options.EncriptID = that.EncriptID;    
            options.action = "devicedetail";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        that.form = data.data;
                        that.ID=that.form.ID; 
                        that.get_wb_data();
                        that.get_xj_data();
                        that.get_wx_data();
                    }
                    else{
                        if(data.error){
                            api.toast({
                                msg: data.error,
                                duration: 2000,
                                location: 'bottom'
                            });
                            return
                        }
                    } 
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },   
        get_wb_data(){
            var that = this;
            var options = {};
            options.action = "getdevicetasktypelist";
            options.DeviceID = that.ID;    
            options.TaskType='device_repair';
            options.StartTime='';
            options.EndTime='';
            options.IsInvalidComplete=0;
            options.pageindex=0;
            options.pagesize=10;
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        that.wbCount=data.data.count;
                        that.wblist=data.data.list;
                    } 
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },   
        get_xj_data(){
            var that = this;
            var options = {};
            options.DeviceID = that.ID;      
            options.action = "getdevicetasktypelist";
            options.TaskType='device_check';
            options.StartTime='';
            options.EndTime='';
            options.IsInvalidComplete=0;
            options.pageindex=0;
            options.pagesize=10;
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        that.xjCount=data.data.count;
                        that.xjlist=data.data.list;
                    } 
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        }, 
        get_wx_data(){
            var that = this;
            var options = {};
            options.DeviceID = that.ID;      
            options.action = "getdeviceservicelistbydeviceid";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if(data.status) {
                        that.wxlist=data.list;
                    } 
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        //查看详情
        doOpenDetail(){
            this.showdetail=!this.showdetail;
        },
        open_details: function(item) {
            ns.openWin('equipment_details_frm_task', '工作记录详情', {
                id: item.ID
            });
        },
        doRecordAdd(){
            var that = this;
            ns.openWin('equipment_addfrm', '新增记录',{
                IsHome:true,//是否是首页
                DeviceID:that.form.ID,
                projectid:that.form.ProjectID,
                name:that.form.ProjectName,
            });
        },
        doOpenMoreRecord(type){
           // type 1-维保  2 巡检
           //类型 device_check-设备巡检 device_repair-设备维保
            var that = this;
            ns.openWin('equipment_homelist', '记录列表', {
                id: that.ID,
                type:type,
            });
        },
    }
});

apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.ID = api.pageParam.ID || 0;
    app.EncriptID = api.pageParam.EncriptID || '';
    app.get_homedata();
    api.addEventListener({
        name: 'reloadhomedetail'
    }, function(ret, err) {
        app.get_homedata();
    });
}
